package cn.ztr.ymcc.mq;

import cn.ztr.ymcc.constance.cons;
import cn.ztr.ymcc.dto.PaySuccessDto;
import cn.ztr.ymcc.service.ICourseUserLearnService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.base.Charsets;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(
        consumerGroup = "PaySuccessConsumer2",
        topic = cons.PAY_SUCCESS_TOPIC_ZTR,
        selectorExpression = cons.PAY_SUCCESS_TARGET_ZTR
)
public class PaySuccessConsumer implements RocketMQListener<MessageExt> {

    @Autowired
    private ICourseUserLearnService courseUserLearnService;

    @Override
    public void onMessage(MessageExt message) {
        byte[] body = message.getBody();
        String s = new String(body, Charsets.UTF_8);
        PaySuccessDto paySuccessDto = JSON.parseObject(s, PaySuccessDto.class);
        courseUserLearnService.save(paySuccessDto);
    }
}
